package com.junshang.JUC_day1;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Created by sahngjun on 2017/3/17.
 */
public class TeatAutom {
    private static AtomicDemo ad = new AtomicDemo();

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            new Thread(ad).start();
        }
    }
}

class AtomicDemo implements Runnable {
    //    private volatile int serialNum=0;
    private AtomicInteger seriaNumber = new AtomicInteger(0);

    public void run() {
        try {
            Thread.sleep(200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(getSerialNum());
    }
//    public int getSerialNum() {
//        return serialNum;
//    }

    public int getSerialNum() {
        return seriaNumber.getAndIncrement();
    }

}
